<template>
  <div class="body">
    <img class="carton" src="./03.png" alt="">
    <div class="wrapper">
    <div class="log"></div>
  </div>
    <div class="left-box" id="left-box">
      <div>
      <div class="red " @click="change" ></div>
      <div class="flex">
        <div class="select-style">
          <div class="select-icon" @click="select"></div>
          <div v-show="this.isShow" class="select-content">
          <div class="color-select">
            <div class="color-title">颜色</div>
            <ul class="all-color">
              <li class="color-n">
                <ul>
                  <li class="color-icon"></li>
                  <li>
                    <input class="colorbox" type="radio" name="1" value="red" @change="change_c" id="">
                  </li>
                </ul>
              </li>
              <li class="color-n">
                <ul>
                  <li class="color-icon"></li>
                  <li>
                    <input class="colorbox" type="radio" name="1" value="green" @change="change_c" id="">
                  </li>
                </ul>
              </li>
              <li class="color-n">
                <ul>
                  <li class="color-icon"></li>
                  <li>
                    <input class="colorbox" type="radio" name="1" value="yellow" @change="change_c" id="">
                  </li>
                </ul>
              </li>
              <li class="color-n">
                <ul>
                  <li class="color-icon"></li>
                  <li>
                    <input class="colorbox" type="radio" name="1" value="cyan" @change="change_c" id="">
                  </li>
                </ul>
              </li>
              <li class="color-n">
                <ul>
                  <li class="color-icon"></li>
                  <li>
                    <input class="colorbox" type="radio" name="1" value="#bfa" @change="change_c" id="">
                  </li>
                </ul>
              </li>
              <li class="color-n">
                <ul>
                  <li class="color-icon"></li>
                  <li>
                    <input class="colorbox" type="radio" name="1" value="#fff" @change="change_c" id="">
                  </li>
                </ul>
              </li>
              <li class="color-n">
                <ul>
                  <li class="color-icon"></li>
                  <li>
                    <input class="colorbox" type="radio" name="1" value="rgba(165, 161, 237, .5)" @change="change_c" id="">
                  </li>
                </ul>
              </li>
            </ul>
          </div>
          <hr>
          </div>
        </div>
          <img class="log-carton" id="log-carton" src="./01.png" alt="">
          <div class="login-box">
        <h3 class="title">登录界面</h3>
        <el-form
          :model="loginForm"
          status-icon
          :rules="rules"
          ref="ruleForm"
          label-width="60px"
          class="demo-ruleForm"
        >
          <el-form-item class="item" label="账号" prop="username">
            <el-input
              type="text"
              v-model="loginForm.username"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item class="item" label="密码" prop="password" >
            <el-input
              type="password"
              v-model="loginForm.password"
              autocomplete="off"
            ></el-input>
          </el-form-item>
          <el-form-item class="button">
            <el-button type="primary" @click="submitForm('ruleForm')"
              >提交</el-button
            >
            <el-button @click="resetForm('ruleForm')">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
      </div>
       
    
      <div class="about-me">
        <h2 class="me">关于我</h2>
        <hr>
        <div class="login-content">
          <span>xxxx</span>&nbsp;/&nbsp;
          <span>xxxx</span>&nbsp;/&nbsp;
          <span>xxxx</span>&nbsp;/&nbsp;
          <span>xxxx</span>&nbsp;&nbsp;
        </div>
      </div>
      </div>
    </div>
  </div>
</template>  

<script>
import jwt from 'jwt-decode'
import {mapMutations} from 'vuex'


 export default {
    data() {
      var validateUser = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入账号'));
        } else {
          callback();
        }
      };
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        }else{
          callback();
        }
      };
      return {
        isShow:false,
        color:["red","green","yellow","cyan","#bfa","#fff","rgba(165, 161, 237, .5)"],
        loginForm: {
          username: '',
          password: '',
        },
        rules: {
          username: [
            { validator: validateUser, trigger: 'blur' }
          ],
          password: [
            { validator: validatePass, trigger: 'blur' }
          ],
        }
      };
    },
    mounted(){
      const div = document.getElementById("left-box")
      div.style.width = "60px"
      div.style.backgroundColor= "rgba(165, 161, 237, .5)"
    },
    methods: {
      ...mapMutations('loginModule',['setUser']),
      // 右边登录展开关闭
      change(){
        const div = document.getElementById("left-box")
        const div2 = document.getElementById("log-carton")
          if(div.clientWidth == 600){
            div.style.animation = "move 2s ease-out 1 normal forwards"
            div2.style.animation = "down 2s ease normal forwards"

          }else{
            div.style.animation = "remove 2s ease-out 1 normal forwards"
            div2.style.animation = "up 2s ease 0.5s normal forwards"
            
          }    
      },
      changeColor(){
        const li = document.getElementsByClassName("color-icon")
        for(let i=0;i<this.color.length;i++){
          li[i].style.backgroundColor = this.color[i]
        }
      },
      change_c(event){
        
        if(event.target.value =="red"){
          const div = document.getElementById("left-box")
          div.style.backgroundColor ="rgba(255,0,255,.5)"
          div.style.opacity =0.5
        }else if(event.target.value =="green"){
          const div = document.getElementById("left-box")
          div.style.backgroundColor ="green"
          div.style.opacity =0.5
        }else if(event.target.value =="yellow"){
          const div = document.getElementById("left-box")
          div.style.backgroundColor ="yellow"
          div.style.opacity =0.5
        }else if(event.target.value =="cyan"){
          const div = document.getElementById("left-box")
          div.style.backgroundColor ="cyan"
          div.style.opacity =0.5
        }else if(event.target.value =="#bfa"){
          const div = document.getElementById("left-box")
          div.style.backgroundColor ="#bfa"
          div.style.opacity =0.5
        }else if(event.target.value =="#fff"){
          const div = document.getElementById("left-box")
          div.style.backgroundColor ="#fff"
          div.style.opacity =0.5
        }else if(event.target.value =="rgba(165, 161, 237, .5)"){
          const div = document.getElementById("left-box")
          div.style.backgroundColor ="rgba(165, 161, 237, .5)"
          div.style.opacity =0.5
        }
         
      },
      //登录页面点击改变颜色背景图
      select(){
        const div = document.getElementsByClassName("select-content")[0]
        this.isShow =!this.isShow
        div.style.animation = "a 0.5s ease normal forwards"
        this.changeColor()
      },
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
           console.log('登录成功！',this.loginForm);
           let {username,password} = this.loginForm;
           //请求实现登录
           this.$api.getLogin({
             username,password
           }).then(res=>{
             console.log('=======' ,res.data)
             if(res.data.status == 200){
               console.log(jwt(res.data.data));
               let obj={
                 user:jwt(res.data.data).username,
                 token:res.data.data
               }
               this.setUser(obj)
               //存储本地
               localStorage.setItem('user',JSON.stringify(obj))
               //登录成功之后跳转
               this.$router.push('/')
               
             }else{
               //账号和密码错误
              this.$message.error('账号或者密码错误')
              //登录成功后：1.存储登录信息、2.跳转网页、3.顶部区域显示用户信息
             }
             
           })
          } else {
            console.log('输入有错！');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style lang="less">
.title{
  margin-bottom: 20px;
  text-align: center;
  color: #fff;
}
.login-box {
  position: absolute;
  width: 400px;
  height: 300px;
  margin-top: 150px;
  margin-left: 80px;
  padding: 20px;
  border-radius: 10px;
  border: 1px solid rgb(88, 155, 241);
  background: #fff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  background: url(./sky.jpg) no-repeat;
  background-size: 100% 100%;
  z-index:99 ;
}
.body{
  width: 1920px;
  position: relative;
  height: 890px;
  background: url(./office.png) no-repeat;
  background-size: 100% 100%;
  overflow: hidden;
}
.item .el-form-item__label {
  color:#fff
}
.log{
  width: 400px;
  height: 400px;
  margin-top: 80px;
  margin-left: 200px;
  background: url(./logo1.png) no-repeat;
  background-size: 100% 100%;
  position: absolute;
  // background: red;
  
}
.button{
  margin-top: 50px;
  margin-left: 80px;
}
.wrapper{
  float: left;
}
.select-style{
  position: absolute;
  margin-top: -40px;
  margin-left: 80px;
  width: 500px;
  height: 180px;
  border-radius: 10px;
}
.select-icon{
  width: 40px;
  height: 40px;
  background-color: red;
  border-radius: 50%;
  right: 0;
  position: absolute;
}
.select-content{
  width: 450px;
  height: 150px;
  margin-top: 30px;
  background-color: #fff;
  position: absolute;
  right: 40px;
  border-radius: 10px;
  z-index: 100;
}
.left-box{
  position: relative;
  width: 600px;
  height: 890px;
  
  float: right;
  // border-left: 2px solid rgb(128, 123, 238);
  box-shadow: 0 0 20px rgba(0, 0, 0,.5);
  background-color: rgba(165, 161, 237, .5);
  // animation: move 5s;
}
.flex{
  display: flex;
}

.about-me{
  width: 600px;
  position: absolute;
  bottom: 140px;
  opacity: 1 !important;
  
}
.me{
  margin-left: 50px;
  z-index: 100;
  font-weight: 900;
}
.login-content{
  margin-left: 70px;
  margin-top: 20px;
}
.carton{
  position: absolute;
  bottom: 0;
  width: 200px;
  height: 200px;
  margin-left: -90px;
}
.carton:hover{
  margin-left: 0px;
  transition: margin-left 0.5s;
}
.log-carton{
  width: 250px;
  height: 150px;
  margin-left: 170px;
  margin-top: 150px;
  z-index:98;
}
.red{
  width: 40px;
  height: 30px;
  margin-left: -40px;
  margin-top: 20px;
  background-color: rgb(181, 83, 233);
  border-radius: 50% 0 0 50%;
}
.red:hover{
  opacity: 0.5;
  transition: opacity linear 0.5s;
  background-color: rgb(187, 101, 234);

}
.color-select{
  width: 400px;
  height: 60px;
  margin-left: 25px;
  margin-top: 5px;
  background-color: rgb(223, 219, 219);
}
.color-title{
  width: 400px;
  height: 20px;
  text-align: center;
  line-height: 20px;
  background-color: rgb(203, 201, 201);
  margin-bottom: 10px;
}
.all-color{
  display: flex;
  // background-color: red;
}
.all-color li{
  width: 10px;
  height: 10px;
  margin-left: 10px;
}
.color-icon{
  width: 12px !important;
  height: 12px !important;
  background-color: red;
  border-radius: 2px;
}
.colorbox{
  margin-left: 0px;
}
@keyframes move {
  0%{
    width: 600px;
  }
  100%{
    width: 50px;
  }
}
@keyframes remove {
  0%{
    width: 50px;
  }
  100%{
    width: 600px;
  }
}
@keyframes up{
  0%{
    margin-top: 150px;
  }
  100%{
    margin-top: 0px;
  }
}
@keyframes down{
  0%{
    margin-top: 0px;
  }
  100%{
    margin-top: 150px;
  }
}
@keyframes a{
  0%{
    opacity: 0;
    margin-right: 0px;
  }
  100%{
    opacity: 0.7;
    margin-right: 10px;
  }
}

</style>